/*
** Haaf's Game Engine 1.7
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** Core functions implementation: HGE splash screen
*/


#include "hge_impl.h"
#include "../../hgesprite.h"

#ifdef DEMO

hgeSprite* spr;
float dtime;
HTEXTURE tex;
int screen_width;
int screen_height;

void DInit() {
	int x=0;
	int y=0;
    screen_width = pHGE->System_GetState(HGE_SCREENWIDTH);
    screen_height = pHGE->System_GetState(HGE_SCREENHEIGHT);

    tex = pHGE->Texture_Load("data/images/intro.png");
	spr = new hgeSprite(tex, 0.0f, 0.0f, (float)pHGE->Texture_GetWidth(tex, true), (float)pHGE->Texture_GetHeight(tex, true));

	dtime=0.0f;
}

void DDone() {
	pHGE->Texture_Free(tex);
	delete spr;
}

bool DFrame() {
    if(pHGE->Input_GetKey() != 0)
        return true;

	BYTE alpha;
	DWORD col;

	dtime+=pHGE->Timer_GetDelta();

	if(dtime<0.25) alpha=(BYTE)((dtime*4)*0xFF);
	else if(dtime<2.0) alpha=0xFF;
	else if(dtime<2.25) alpha=(BYTE)((1.0f-(dtime-1.0f)*4)*0xFF);
	else return true;

	col=0xFFFFFF | (alpha<<24);
    spr->SetColor(col);

	pHGE->Gfx_BeginScene();
	pHGE->Gfx_Clear(0);
	spr->RenderStretch(0.0f, 0.0f, (float)screen_width, (float)screen_height);
	pHGE->Gfx_EndScene();

	return false;
}

#endif
